package com.hyt.it.ogt.pj.service.impl;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hyt.core.base.BaseServiceImpl;
import com.hyt.it.ogt.pj.mapper.TaskTimeMapper;
import com.hyt.it.ogt.pj.model.entity.TaskTime;
import com.hyt.it.ogt.pj.model.vo.TaskTimeVo;
import com.hyt.it.ogt.pj.service.ITaskTimeService;


/**
 * <p>
 * 评卷时间 服务实现类
 * </p>
 *
 * @author liy
 * @since 2022-02-28
 */
@Service
public class TaskTimeServiceImpl extends BaseServiceImpl<TaskTimeMapper,TaskTime> implements ITaskTimeService {


    @Autowired
    private TaskTimeMapper taskTimeMapper;

    @Override
    public List<TaskTimeVo> queryTaskTimeList(String projectId,String markModel ) {
        QueryWrapper<TaskTime> wrapper = new  QueryWrapper();
        wrapper.lambda().eq(TaskTime :: getProjectId,projectId);
        wrapper.groupBy(getGroupBy(markModel));
        List<TaskTime> taskTimes = taskTimeMapper.selectList(wrapper);
        if(CollectionUtils.isEmpty(taskTimes)){
            return Collections.EMPTY_LIST;
        }
        List<TaskTimeVo> taskTimeVos = new ArrayList<>(taskTimes.size());
        for (TaskTime taskTime:taskTimes) {
            TaskTimeVo vo = new TaskTimeVo();
            BeanUtils.copyProperties(taskTime,vo);
            taskTimeVos.add(vo);
        }
        return taskTimeVos;
    }

    private String getGroupBy(String markModel){
        //0：按科目评卷，1：按批次评卷，2：按考场评卷
        String groupBy = "subject_id";
        if(StringUtils.isEmpty(markModel)){
            return groupBy;
        }
        switch ( markModel ) {
            case "0" :groupBy = "subject_id";break;
            case "1" :groupBy = "batch_id";break;
            default :groupBy = "subject_id";break;
        }
        return  groupBy;
    }
}
